package com.wdc;

import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.function.IntPredicate;

public class LambdaDemo01 {

    public static void main(String[] args) {
        new Thread(() ->System.out.println("新线程执行了2")).start();

        System.out.println(calculateNum(new IntBinaryOperator() {
            @Override
            public int applyAsInt(int left, int right) {
                return left * right;
            }
        }));

        System.out.println(calculateNum((a ,b) -> a +b));

        printNum(value -> value%2 ==0);


        System.out.println(typeConver((Function<String, Integer>) s -> Integer.valueOf(s)));

        System.out.println(typeConver((String s) ->{

            return Integer.valueOf(s);
        }));

    }

    public static int calculateNum(IntBinaryOperator operator){
        int a = 10;
        int b = 20;
        return operator.applyAsInt(a,b);
    }


    public static void printNum(IntPredicate intPredicate){
        int[] arr = {1,2,3,4,5,6,7,8,9,10};
        for (int i : arr) {
            if (intPredicate.test(i)){
                System.out.println(i);

            }
        }
    }

    public static <R> R typeConver(Function<String,R> function){
        String str = "123";

        return function.apply(str);
    }

}
